                include Common.asm

; ==========================================================
DataSeg         segment para public 'data'

	LblLine1	NearPtr 0
	LblLine2	NearPtr 0
	LblLine3	NearPtr 0
	BtnOk		NearPtr 0
	BtnCancel	NearPtr 0

	DialogTitle	NearPtr 0
        DialogLine1	NearPtr 0
        DialogLine2	NearPtr 0
        DialogLine3	NearPtr 0
        TxtOk		db "Yes",0
        TxtCancel	db "No",0

        DlgConfirmClass  TWndClass { DlgConfirmOnInit, DlgConfirmOnCleanUp,
                DlgConfirmOnDraw, DlgConfirmOnProcess,
                DlgConfirmOnKey, DlgConfirmOnMouse, DlgConfirmOnCommand }

DataSeg         ends

; ==========================================================
CodeSeg         segment para public 'code'
        assume  ds: DataSeg


; ----------------------------------------------------------
; CreateDlgConfirm - DlgConfirm OnInit Handler
; ----------------------------------------------------------
; Input:	none
; Output:
;	si	pointer to created dialog window
; ----------------------------------------------------------
CreateDlgConfirm	proc

	push	bx

	call	AllocWndData
	mov	si, offset DlgConfirmClass
	mov	[bx].TWndData.WndClass, si
	mov	si, bx

	pop	bx	
	ret

CreateDlgConfirm	endp


; ----------------------------------------------------------
; DlgConfirmOnInit - DlgConfirm OnInit Handler
; ----------------------------------------------------------
; Input:
;       si      Pointer to WndData
; Output:       none
; ----------------------------------------------------------
DlgConfirmOnInit proc near

	push    bx
	push    dx
	push    si
	push    di

	mov	bx, si
	mov     [bx].TWndData.SizeX, 220
	mov     [bx].TWndData.SizeY, 90
	push	si
	mov     si, DialogTitle
	lea     di, [bx].TWndData.Text
	call	StrCopy
	pop	si

	mov     [si].TWndData.Color, ColorDarkGray
	mov     dx, si

	; LblLine1
	call    AllocWndData
	mov     [bx].TWndData.WndClass, offset LabelClass
	mov     [bx].TWndData.X, 10
	mov     [bx].TWndData.Y, 20
	mov     [bx].TWndData.SizeX, 200
	mov     [bx].TWndData.SizeY, 20
	mov     si, DialogLine1
	lea     di, [bx].TWndData.Text
	call	StrCopy
	mov	si, bx
	mov     di, dx
	call    AddChildWnd
        mov     LblLine1, bx

	; LblLine2
	call    AllocWndData
	mov     [bx].TWndData.WndClass, offset LabelClass
	mov     [bx].TWndData.X, 10
	mov     [bx].TWndData.Y, 30
	mov     [bx].TWndData.SizeX, 200
	mov     [bx].TWndData.SizeY, 20
	mov     si, DialogLine2
	lea     di, [bx].TWndData.Text
	call	StrCopy
	mov	si, bx
	mov     di, dx
	call    AddChildWnd
        mov     LblLine2, bx

	; LblLine3
	call    AllocWndData
	mov     [bx].TWndData.WndClass, offset LabelClass
	mov     [bx].TWndData.X, 10
	mov     [bx].TWndData.Y, 40
	mov     [bx].TWndData.SizeX, 200
	mov     [bx].TWndData.SizeY, 20
	mov     si, DialogLine3
	lea     di, [bx].TWndData.Text
	call	StrCopy
	mov	si, bx
	mov     di, dx
	call    AddChildWnd
        mov     LblLine3, bx

	; BtnOk
	call    AllocWndData
	mov     [bx].TWndData.WndClass, offset ButtonClass
	mov     [bx].TWndData.X, 10
	mov     [bx].TWndData.Y, 60
	mov     [bx].TWndData.SizeX, 95
	mov     [bx].TWndData.SizeY, 20
	mov     si, offset TxtOk
	lea     di, [bx].TWndData.Text
	call	StrCopy
	mov	si, bx
	mov     di, dx
	call    AddChildWnd
	mov     BtnOk, bx

	; BtnCancel
	call    AllocWndData
	mov     [bx].TWndData.WndClass, offset ButtonClass
	mov     [bx].TWndData.X, 115
	mov     [bx].TWndData.Y, 60
	mov     [bx].TWndData.SizeX, 95
	mov     [bx].TWndData.SizeY, 20
	mov     si, offset TxtCancel
	lea     di, [bx].TWndData.Text
	call	StrCopy
	mov	si, bx
	mov     di, dx
	call    AddChildWnd
	mov     BtnCancel, bx

	pop     di
	pop     si
	pop     dx
	pop     bx

	ret

DlgConfirmOnInit endp


; ----------------------------------------------------------
; DlgConfirmOnCleanUp - DlgConfirm OnCleanUp Handler
; ----------------------------------------------------------
; Input:
;       si      Pointer to WndData
; Output:       none
; ----------------------------------------------------------
DlgConfirmOnCleanUp      proc near

	push    si

	mov     si, LblLine1
	call    DeleteChildWnd

	mov     si, LblLine2
	call    DeleteChildWnd

	mov     si, LblLine3
	call    DeleteChildWnd

	mov     si, BtnOk
	call    DeleteChildWnd

	mov     si, BtnCancel
	call    DeleteChildWnd

	pop     si

	ret

DlgConfirmOnCleanUp      endp


; ----------------------------------------------------------
; DlgConfirmOnDraw - DlgConfirm OnDraw Handler
; ----------------------------------------------------------
; Input:
;       si      Pointer to WndData
; Output:       none
; ----------------------------------------------------------
DlgConfirmOnDraw proc near

        push    ax
        mov     ax, 0
        push    ax
        push    ax
        push    [si].TWndData.SizeX
        push    [si].TWndData.SizeY
        mov     ah, 0
        mov     al, [si].TWndData.Color
        push    ax
        call    FillRect
        pop     ax

	call	DefMovingWndOnDraw

        ret

DlgConfirmOnDraw endp


; ----------------------------------------------------------
; DlgConfirmOnProcess - DlgConfirm OnProcess Handler
; ----------------------------------------------------------
; Input:
;       si      Pointer to WndData
; Output:       none
; ----------------------------------------------------------
DlgConfirmOnProcess      proc near

        ret

DlgConfirmOnProcess      endp


; ----------------------------------------------------------
; DlgConfirmOnMouse - DlgConfirm OnMouse Handler
; ----------------------------------------------------------
; Input:
;       si      Pointer to WndData
; Output:       none
; ----------------------------------------------------------
DlgConfirmOnMouse        proc near

        call    DefWndOnMouse

        call    DefMovingWndOnMouse

        ret

DlgConfirmOnMouse        endp


; ----------------------------------------------------------
; DlgConfirmOnKey - DlgConfirm OnKey Handler
; ----------------------------------------------------------
; Input:
;       si      Pointer to WndData
; Output:       none
; ----------------------------------------------------------
DlgConfirmOnKey  proc

        cmp     EventData.EventType, EvtKeyPressed
        jne     SkipStageKeyPressed

        jmp     SkipStageKeyPressed

QKeyPressed:
        mov     Terminated, 1
        inc     [si].TWndData.Color

SkipStageKeyPressed:

        ret

DlgConfirmOnKey  endp


; ----------------------------------------------------------
; DlgConfirmOnCommand - DlgConfirm OnCommand Handler
; ----------------------------------------------------------
; Input:
;       si      Pointer to WndData
; Output:       none
; ----------------------------------------------------------
DlgConfirmOnCommand      proc near

	local	valueBoardSizeX: word, valueBoardSizeY: word, 
		valueMineCount: word, maxMineCount: word

	push	ax
	push	bx
	push	dx
	push	si

        mov     bx, CommandData.Sender

        cmp     bx, BtnOk
        jne     DoneBtnOk

	mov	ModalResult, ModalResultOk
        mov     NextStageClass, offset MenuStageClass
	jmp	DoneBtnOk

InvalidValue:
	call	Beep
	jmp	DoneBtnOk

DoneBtnOk:
        cmp     bx, BtnCancel
        jne     SkipBtnCancel

	mov	ModalResult, ModalResultCancel

SkipBtnCancel:
SkipBtnQuit:

	pop	si
	pop	dx
	pop	bx
	pop	ax
        ret

DlgConfirmOnCommand      endp

CodeSeg         ends

                end

